<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>bkn.bibtex.comparisons</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="bkn.bibtex-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://code.google.com/p/bibkn/">bkn.bibtex</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        Package&nbsp;bkn ::
        <a href="bkn.bibtex-module.html">Package&nbsp;bibtex</a> ::
        Module&nbsp;comparisons
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="bkn.bibtex.comparisons-module.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== MODULE DESCRIPTION ==================== -->
<h1 class="epydoc">Module comparisons</h1><p class="nomargin-top"><span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html">source&nbsp;code</a></span></p>
<p>Useful comparison functions for sorting bibliographies.</p>
  <p>These comparison functions, like the built-in function 
  <code>cmp</code>, take two arguments and return a negative number if the 
  first comes before the second and a positive number if the second comes 
  before the first. They may be used as an argument to the built in sort 
  function or to the Bibliography.sort() instance method.</p>

<hr />
<div class="fields">      <p><strong>Copyright:</strong>
        (c) 2010, Benjamin Kalish
      </p>
      <p><strong>License:</strong>
        This program is free software; you can redistribute it and/or 
        modify it under the terms of the GNU General Public License as 
        published by the Free Software Foundation; either version 2 of the 
        License, or (at your option) any later version.
        <p>This program is distributed in the hope that it will be useful, 
        but WITHOUT ANY WARRANTY; without even the implied warranty of 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
        General Public License for more details.</p>
      </p>
</div><!-- ==================== FUNCTIONS ==================== -->
<a name="section-Functions"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Functions</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-Functions"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code>int</code></span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="bkn.bibtex.comparisons-module.html#compare_names" class="summary-sig-name">compare_names</a>(<span class="summary-sig-arg">a</span>,
        <span class="summary-sig-arg">b</span>)</span><br />
      Compares two strings representing names.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_names">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code>int</code></span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="bkn.bibtex.comparisons-module.html#compare_name_strings" class="summary-sig-name">compare_name_strings</a>(<span class="summary-sig-arg">a</span>,
        <span class="summary-sig-arg">b</span>)</span><br />
      Compare two strings, which may be lists of authors, as found in 
      BibTex.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_name_strings">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code>int</code></span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="bkn.bibtex.comparisons-module.html#compare_year_strings" class="summary-sig-name">compare_year_strings</a>(<span class="summary-sig-arg">a</span>,
        <span class="summary-sig-arg">b</span>)</span><br />
      Compare two strings each of which represent a year.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_year_strings">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr class="private">
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code>int</code></span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="bkn.bibtex.comparisons-module.html#_year_for_sort" class="summary-sig-name" onclick="show_private();">_year_for_sort</a>(<span class="summary-sig-arg">year_string</span>)</span><br />
      Returns the first sequence of four digits found in the string, or a 
      very large integer if no such sequence is found.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#_year_for_sort">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code>int</code></span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="bkn.bibtex.comparisons-module.html#compare_titles" class="summary-sig-name">compare_titles</a>(<span class="summary-sig-arg">a</span>,
        <span class="summary-sig-arg">b</span>)</span><br />
      Compares titles, ignoring case, punctuation, and accents.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_titles">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type"><code>int</code></span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="bkn.bibtex.comparisons-module.html#compare_entries" class="summary-sig-name">compare_entries</a>(<span class="summary-sig-arg">a</span>,
        <span class="summary-sig-arg">b</span>)</span><br />
      A standard comparison used for sorting bibliographies.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_entries">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
<!-- ==================== FUNCTION DETAILS ==================== -->
<a name="section-FunctionDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Function Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-FunctionDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="compare_names"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">compare_names</span>(<span class="sig-arg">a</span>,
        <span class="sig-arg">b</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_names">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Compares two strings representing names.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>a</code></strong> (<code>Unicode</code>) - a name</li>
        <li><strong class="pname"><code>b</code></strong> (<code>Unicode</code>) - a name</li>
    </ul></dd>
    <dt>Returns: <code>int</code></dt>
        <dd>a negative integer if <code>a</code> should come first, a 
          positive integer if <code>b</code> should come first, and 0 if 
          <code>a</code> and <code>b</code> are equal.</dd>
  </dl>
<div class="fields">      <strong>To Do:</strong>
      <ul class="nomargin-top">
        <li>
        create a Name object and modify this method to work with Name objects 
    as well as strings.
        </li>
        <li>
        add error handling in case invalid arguments are passed
        </li>
        <li>
        document method of comparison
        </li>
        <li>
        This method is long! Consider refactoring!
        </li>
      </ul>
</div></td></tr></table>
</div>
<a name="compare_name_strings"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">compare_name_strings</span>(<span class="sig-arg">a</span>,
        <span class="sig-arg">b</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_name_strings">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Compare two strings, which may be lists of authors, as found in 
  BibTex.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>a</code></strong> (<code>Unicode</code>) - a list of authors' names as found in BibTeX</li>
        <li><strong class="pname"><code>b</code></strong> (<code>Unicode</code>) - a list of authors' names as found in BibTeX</li>
    </ul></dd>
    <dt>Returns: <code>int</code></dt>
        <dd>a negative integer if <code>a</code> should come first, a 
          positive integer if <code>b</code> should come first, and 0 if 
          <code>a</code> and <code>b</code> are equal.</dd>
  </dl>
<div class="fields">      <p><strong>To Do:</strong>
        This or a similar method should take either a list of strings or a list
    of Name objects.
      </p>
</div></td></tr></table>
</div>
<a name="compare_year_strings"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">compare_year_strings</span>(<span class="sig-arg">a</span>,
        <span class="sig-arg">b</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_year_strings">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Compare two strings each of which represent a year.</p>
  <p>This function is mildly tolerant of irregularities in the specified 
  years.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>a</code></strong> (<code>Unicode</code>) - a string containing a four-digit year</li>
        <li><strong class="pname"><code>b</code></strong> (<code>Unicode</code>) - a string containing a four-digit year</li>
    </ul></dd>
    <dt>Returns: <code>int</code></dt>
        <dd>a negative integer if <code>a</code> should come first, a 
          positive integer if <code>b</code> should come first, and 0 if 
          <code>a</code> and <code>b</code> are equal.</dd>
  </dl>
<div class="fields">      <p><strong>Note:</strong>
        This method assumes that the year is given by first sequence of 
        four digits found in the string. Ties will be broken by comparing 
        the entire string. And a string with no such sequence will come 
        after a string with such a sequence.
      </p>
</div></td></tr></table>
</div>
<a name="_year_for_sort"></a>
<div class="private">
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">_year_for_sort</span>(<span class="sig-arg">year_string</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#_year_for_sort">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Returns the first sequence of four digits found in the string, or a 
  very large integer if no such sequence is found.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>year_string</code></strong> (<code>Unicode</code>) - a string containing a four-digit year</li>
    </ul></dd>
    <dt>Returns: <code>int</code></dt>
        <dd>the integer value of the first four consecutive digits found in 
          <code>year_string</code></dd>
  </dl>
</td></tr></table>
</div>
<a name="compare_titles"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">compare_titles</span>(<span class="sig-arg">a</span>,
        <span class="sig-arg">b</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_titles">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>Compares titles, ignoring case, punctuation, and accents.</p>
  <p>This method ignores capitalization and the initial articles 
  &quot;the&quot;, &quot;a&quot;, and &quot;an&quot;.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>a</code></strong> (<code>Unicode</code>) - a title</li>
        <li><strong class="pname"><code>b</code></strong> (<code>Unicode</code>) - a title</li>
    </ul></dd>
    <dt>Returns: <code>int</code></dt>
        <dd>a negative integer if <code>a</code> should come first, a 
          positive integer if <code>b</code> should come first, and 0 if 
          <code>a</code> and <code>b</code> are equal.</dd>
  </dl>
</td></tr></table>
</div>
<a name="compare_entries"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">compare_entries</span>(<span class="sig-arg">a</span>,
        <span class="sig-arg">b</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="bkn.bibtex.comparisons-pysrc.html#compare_entries">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <p>A standard comparison used for sorting bibliographies.</p>
  <p>Sorts by year, then author (or editor) and finally by title.</p>
  <dl class="fields">
    <dt>Parameters:</dt>
    <dd><ul class="nomargin-top">
        <li><strong class="pname"><code>a</code></strong> (<a href="bkn.bibtex.bibliography.Record-class.html" 
          class="link">Record</a>) - a bibliography entry</li>
        <li><strong class="pname"><code>b</code></strong> (<a href="bkn.bibtex.bibliography.Record-class.html" 
          class="link">Record</a>) - a bibliography entry</li>
    </ul></dd>
    <dt>Returns: <code>int</code></dt>
        <dd>a negative integer if <code>a</code> should come first, a 
          positive integer if <code>b</code> should come first, and 0 if 
          <code>a</code> and <code>b</code> are equivalent for sorting 
          purposes.</dd>
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">
  <!-- Home link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="bkn.bibtex-module.html">Home</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://code.google.com/p/bibkn/">bkn.bibtex</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Sun Jul  4 23:10:58 2010
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
